package com.wx.rabbitmq.limiting;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.wx.rabbitmq.MqConnection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import static com.wx.rabbitmq.limiting.Consumer.EXCHANGE_DIREC_QOS;


/**
 * @author wx
 * @Description: 生产者-限流
 * @date 2018/11/23 002316:57
 */
public class Producer {
    public static void main(String[] agrs) throws IOException, TimeoutException {
        //1.获取connection
        Connection connection = MqConnection.getConnection();

        //2.通过connection创建一个Channel
        Channel channel = connection.createChannel();
        //3.指定我们的消息投递模式: 消息的确认模式
        channel.confirmSelect();

        String routingKey = "qos.save";
        String msg = "Hello RabbitMQ QOS Message";

        for (int i = 0; i < 100; i++) {
            //4. 通过Channel发送数据   exchange=交换机、 2 routingKey=队列对应的key、3 props = 消息装饰器、 4=消息体
            channel.basicPublish(EXCHANGE_DIREC_QOS, routingKey, true, null, msg.getBytes());
        }

        //5 记得要关闭相关的连接
        channel.close();
        connection.close();
    }
}
